package com.wwwarehouse.resource_center.fragment.createobject.createtools;

import android.os.Bundle;
import android.view.View;
import android.widget.EditText;

import com.wwwarehouse.common.activity.base.BaseActivity;
import com.wwwarehouse.common.bean.response.CommonClass;
import com.wwwarehouse.resource_center.R;
import com.wwwarehouse.resource_center.customView.AutoClickButton;
import com.wwwarehouse.resource_center.eventbus_event.StringEvent;
import com.wwwarehouse.resource_center.fragment.rules.TheParentFragment;

import de.greenrobot.event.EventBus;

/**
 * @author Joseph on 2017/9/15.
 *         <p/>
 *         添加商品描述
 */

public class ToolsDescripFragment extends TheParentFragment {

    private AutoClickButton mBtn;
    private EditText mEtText;

    @Override
    protected int getContentId() {
        return R.layout.fragment_goods_descrip;
    }

    @Override
    protected void init(View view) {
        mEtText = findView(view, R.id.goods_descrip);
        mBtn = findView(view, R.id.confirm_btn);
        mBtn.bindEditText(mEtText);
        Bundle bundle = getArguments();
        if (bundle != null) {
            String des = bundle.getString("des");
            if (des != null && !des.isEmpty())
                mEtText.setText(bundle.getString("des"));
        }
        ((BaseActivity) mActivity).hideSoftByEditViewIds(new int[]{R.id.goods_descrip});
    }

    @Override
    public void setTitle() {
        if (peekFragment() instanceof ToolsDescripFragment)
            mActivity.setTitle(getString(R.string.tool_descrip));
    }

    @Override
    protected void loadDatas() {
        mBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                EventBus.getDefault().post(new StringEvent("descrip", mEtText.getText().toString()));
            }
        });
    }

    @Override
    public void onSuccess(CommonClass commonClass, int what) {

    }

    @Override
    public void onReLoad(int code) {

    }
}
